﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data.SqlClient;
using System.Configuration;

namespace B10.Controllers
{
    public class PreviewController : Controller
    {
        //
        // GET: /Preview/

        public void Track(int id)
        {
            SqlConnection connection = null;
            try
            {
                string ip = Request.ServerVariables["REMOTE_ADDR"];
                connection = new SqlConnection(
                    ConfigurationManager.ConnectionStrings["B10ConnectionString"].ConnectionString);
                SqlCommand cmd = connection.CreateCommand();
                cmd.CommandText = "TrackPreview";
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@PageId", id));
                cmd.Parameters.Add(new SqlParameter("@IP", ip));
                connection.Open();
                cmd.ExecuteNonQuery();
            }
            catch
            {
                //Log
            }
            finally
            {
                if (connection != null)
                    connection.Close();
            }
        }

    }
}
